package com.stackfarm.fvcommon.utils;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class UserUtils {
    //密码(最少6位,最多15位，只能有字母数字,.?!)
    private static final Pattern PASSWORD_PATTERN= Pattern.compile("^[A-Za-z0-9,.?!]{6,15}$");
    //用户名(只能包括数字字母的组合，长度为4-15位)
    private static final Pattern USERNAME_PATTERN=Pattern.compile("^[A-Za-z0-9]{4,15}$");
    public static String getSalt(){
        int val = new Random().nextInt() % 999999;
        val = Math.abs(val);
        String salt = String.format("%06d", val);
        salt += UUID.randomUUID().toString().replace("-", "").substring(0, 12).toUpperCase();
        return salt;
    }
    public static boolean UserIsValidate(String username){
        Matcher matcher=USERNAME_PATTERN.matcher(username);
        return matcher.matches();
    }
    public static boolean PasswordIsValidate(String password){
        Matcher matcher = PASSWORD_PATTERN.matcher(password);
        return matcher.matches();
    }
}
